﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using Base.Data;
using Base.Custom;
using Base.Extensions;
public enum RlitType
{
    不启用右键菜单,
    启用右键菜单
}
public enum 菜单类型
{
    默认,
    关系菜单右键,
    关系菜单重命名
}
public class Relationship : MonoBehaviour {
   
    private int foldsum;
    private GameObject fold;
    private GameObject Content;
    private bool IsEnter;
    private RelationData data;
    public RlitType rlit;
    public 菜单类型 菜单类型;
    public RelationshipPanel 系统关系界面;
    public InputField 系统关系名字输入;
    public InputField 系统开关名字输入;
    private int sum;
    private bool down=false;
    private float item;
	// Use this for initialization
	void Start () {
        IsEnter = false;
        fold = transform.Find("Title/Fold/Text").gameObject;
        Content = transform.Find("Content").gameObject;
        Content.SetActive(false);
        data = GetComponent<RelationData>();
    }
	
	// Update is called once per frame
	void Update () {
        if (Content.transform.childCount == 0)
            fold.transform.SetEnable<Text>(false);
        else
            fold.transform.SetEnable<Text>(true);
        if (Input.GetMouseButtonDown(1))
        {
            if (IsEnter)
            {
                switch (菜单类型)
                {
                    case 菜单类型.默认:
                        break;
                    case 菜单类型.关系菜单右键:
                        系统关系界面.右键事件(Input.mousePosition, data);
                        print(Input.mousePosition);
                        break;
                    case 菜单类型.关系菜单重命名:
                        系统关系界面.右键事件(Input.mousePosition, data);
                        break;
                }
            }
            else
            {

            }
        }




    }
    IEnumerator 双击延迟判断(float item)
    {
        yield return new WaitForSeconds(item);
        sum = 0;
    }
    public void foldOnClick(Text conts)
    {
        foldsum++;
        if (foldsum % 2 == 0)
        {
            conts.text = "+";
            Content.SetActive(false);
        }
        else
        {
            conts.text = "-";
            Content.SetActive(true);
        }
    }
    public void pipelineOnClick(Text name)
    {
        switch (菜单类型)
        {
            case 菜单类型.默认:
                break;
            case 菜单类型.关系菜单右键:
                break;
            case 菜单类型.关系菜单重命名:
                StartCoroutine(双击延迟判断(0.2f));
                sum++;
                if (sum >= 2)
                {
                    name.GetComponent<InputField>().enabled = true;
                }
                RelationPath path = Dictionaries.relationpath.Find(s => s.code == data.code);
                if (path!=null)
                {
                    foreach (var item in path.objID)
                    {
                        SingleObject sobj = Dictionaries.SingleObject.GetKeyValue<string, SingleObject>(item);
                        sobj.SetHighlighter(Color.blue);
                    }
                }
                break;
        }
    }
    public void valveOnClick(Text name)
    {
        switch (菜单类型)
        {
            case 菜单类型.默认:
                break;
            case 菜单类型.关系菜单右键:
                break;
            case 菜单类型.关系菜单重命名:
                StartCoroutine(双击延迟判断(0.2f));
                sum++;
                if (sum >= 2)
                {
                    name.GetComponent<InputField>().enabled = true;
                }
                RelationPath path = Dictionaries.relationpath.Find(s => s.code == data.code);
                if (path != null)
                {
                    foreach (var item in path.objID)
                    {
                        SingleObject sobj = Dictionaries.SingleObject.GetKeyValue<string, SingleObject>(item);
                        sobj.SetHighlighter(Color.blue);
                    }
                }
                break;
        }
    }
    public void Enter()
    {
        IsEnter = true;
    }
    public void Exit()
    {
        IsEnter = false;
    }
}
